import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 获取用户输入的文本
        System.out.println("请输入要搜索的文本:");
        String text = scanner.nextLine();

        // 获取用户输入的子字符串
        System.out.println("请输入要查找的子字符串:");
        String word = scanner.nextLine();

        // 调用函数计算出现次数
        int count = countOccurrences(word, text);

        // 输出结果
        System.out.println("'" + word + "' 在文本中出现了 " + count + " 次。");

        scanner.close();
    }

    public static int countOccurrences(String word, String text) {
        int count = 0;
        int index = 0;

        // 循环查找子字符串
        while ((index = text.indexOf(word, index)) != -1) {
            count++;
            index += word.length(); // 移动索引到找到的子字符串之后
        }

        return count;
    }
}